//
//  NSString+Fit.m
//  TravelGuideMdd
//
//  Created by BigPolarBear on 14-8-4.
//  Copyright (c) 2014年 mafengwo.com. All rights reserved.
//

#import "NSString+Fit.h"

@implementation NSString (Fit)

-(CGFloat)heightWithFont:(UIFont*)font
                   width:(CGFloat)width
           numberOfLines:(NSInteger)numberOfLines
{
    UILabel* label = [[UILabel alloc] init];
    label.font = font;
    label.numberOfLines = numberOfLines;
    label.text = self;
    
    CGSize size = [label sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)];
    
    return size.height;
}

-(CGFloat)widthWithFont:(UIFont *)font
                 height:(CGFloat)height
          numberOfLines:(NSInteger)numberOfLines
{
    UILabel* label = [[UILabel alloc] init];
    label.font = font;
    label.numberOfLines = numberOfLines;
    label.text = self;
    
    CGSize size = [label sizeThatFits:CGSizeMake(CGFLOAT_MAX, height)];
    
    return size.width;
}

@end
